﻿using Application.DictTypeService;
using AutoMapper;
using Domain.Entity;
using Domain.Entity.sys;
using Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.DictDataService
{
    public class DictDataService : IDictDataService
    {
        private readonly IDictDataRepository dictDataRepository;
        private readonly IMapper mapper;

        public DictDataService(IDictDataRepository dictDataRepository,IMapper mapper)
        {
            this.dictDataRepository = dictDataRepository;
            this.mapper = mapper;
        }

        //添加字典数据
        public async Task<int> AddDictData(AddDictDataDto addDictDataDto)
        {
            //转换
            DictData dictData = mapper.Map<DictData>(addDictDataDto);
            return await dictDataRepository.AddDictData(dictData);
        }

        //删除字典数据
        public async Task<int> DeleteDictData(int id)
        {
            return await dictDataRepository.DeleteDictData(id);
        }

        //根据字典类型查询数据
        public async Task<List<DictData>> GetAllDictDataBytype(int typeid)
        {
            return await dictDataRepository.GetAllDictDataBytype(typeid);
        }

        //根据id查询字典数据
        public async Task<DictData> GetDictDataById(int id)
        {
            return await dictDataRepository.GetDictDataById(id);
        }

        //根据字典类型分页查询字典数据
        public async Task<FenYe<DictData>> GetDictDataByType(FenYe<DictData> fenYe, string? label, int? status, string? createname, string? starttime, string? endtime, int typeid)
        {
            return await dictDataRepository.GetDictDataByType(fenYe, label, status, createname, starttime, endtime, typeid);
        }

        //修改字典数据
        public async Task<int> UpdateDictData(UpdateDictDataDto updateDictDataDto)
        {
            //转换
            DictData dictData = mapper.Map<DictData>(updateDictDataDto);
            return await dictDataRepository.UpdateDictData(dictData);
        }

    }
}
